<template>
	<view class="change_phone">
		<view class="form_content">
			<u-form>
				<u-form-item class="item">
					<u-input placeholder="请输入手机号" prefixIcon="phone" border="false" v-model="mobile"></u-input>
				</u-form-item>
				<u-form-item>
					<u-input placeholder="请输入验证码" prefixIcon="email" border="false"  v-model="captcha">
						<template slot="suffix">
							<button class="code_btn" :disabled="dis"
								@click.prevent="getCode()">{{dis?`重新获取${wait}`:'获取验证码'}}</button>
						</template>
					</u-input>
				</u-form-item>
			</u-form>
		</view>
		<button class="sumbit_btn" @click="sumbit()">提交</button>
	</view>
</template>

<script>
	import {resetphone} from '../../api/index.js'
	export default {
		data() {
			return {
				dis:false,
				wait:60,
				mobile:'',
				captcha:'',
			}
		},
		methods: {
			getCode(){
				if (this.mobile == "") {
					uni.showToast({
						icon: 'error',
						title: '请先填写手机号'
					})
					return
				}
				let data ={
					mobile:this.mobile,
					event:'changemobile'
				}
				getCodes(data).then(res=>{
						this.debonce()
					})
			},
			debonce() {
				console.log(111);
				this.dis = true
				let p = setInterval(() => {
					this.wait--
					if (this.wait === 0) {
						this.dis = false
						this.wait = 60;
						clearInterval(p)
					}
			
				}, 1000)
			},
			sumbit(){
				let data={
					mobile:this.mobile,
					captcha:this.captcha
				}
				resetphone(data).then(res=>{
					console.log(res);
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.change_phone {
		width: 100vw;
		height: 100vh;
		background-color: #FAFAFA;
		padding: 32rpx;
		box-sizing: border-box;

		.new_phone {
			width: 100%;
			height: 44rpx;
			text-align: center;
			line-height: 44rpx;
			color: #333333;
			font-size: 28rpx;
			font-weight: bold;
			margin-top: 80rpx;
		}

		.tips {
			width: 100%;
			height: 44rpx;
			font-size: 28rpx;
			text-align: center;
			line-height: 44rpx;
			color: #666666;
			margin-top: 16rpx;
		}
	}

	.form_content {
		width: 100%;
		height: 208rpx;
		box-sizing: border-box;
		padding: 0rpx 32rpx;
		margin-top: 40rpx;
		background-color: #FFFFFF;
	}

	.code_btn {
		width: 170rpx;
		height: 56rpx;
		font-size: 20rpx;
		line-height: 56rpx;
		color: #FFFFFF;
		text-align: center;
		background: rgba(0, 204, 123, 0.3);
		border-radius: 4rpx 4rpx 4rpx 4rpx;
	}

	.item {
		width: 100%;
		height:104rpx;
		//background-color: red;
		border-bottom: 2rpx #FAFAFA solid;
	}
	.sumbit_btn{
		width: 100%;
		height: 88rpx;
		border-radius: 74rpx;
		color: #FFFFFF;
		background-color: #00CC7B;
		font-size: 32rpx;
		font-weight: bold;
		margin-top: 112rpx;
		opacity: 0.3;
	}
</style>
